package first_practice;

import java.util.*;

public class Solution49 {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            // 遍历strs中的元素，将其排序的String当作key，其value是字母异位词
            char[] s = str.toCharArray();
            Arrays.sort(s);
            map.computeIfAbsent(new String(s), key -> new ArrayList<>()).add(str); // computeIfAbsent返回value
        }
        return new ArrayList<>(map.values());
    }
}
